<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*,
com.brother.model.*, org.apache.commons.lang.*" pageEncoding="utf-8"%>
<jsp:useBean id="userService" class="com.brother.service.UserService"></jsp:useBean>

<%
com.brother.model.Customer loginUser = (com.brother.model.Customer)session.getAttribute(com.brother.Constants.LOGIN_SESSTION_NAME);
if(loginUser ==null){
	return;
}
String action = request.getParameter("action");
if(action != null && action.equalsIgnoreCase("delete")){
	String userid = request.getParameter("userid");
	userService.deleteUser(loginUser, Integer.parseInt(userid));
}

List<Customer> users = userService.getChildUsers(loginUser.getUserid(), null);

%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Users</title>
<link href="../common.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../common.js"></script>
</head>
<body>
<form name="form1" method="post" action="">
	<table width="100%"><tr><td height="30"><div align="left"><a href="addUser.jsp?action=add">Add User </a></div></td></tr></table>
  <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#00CCFF">
    
    <tr>
      <th width="181" height="30" bgcolor="#FFFFFF"><div align="center">Name</div></th>
      <th width="845" bgcolor="#FFFFFF"><div align="center">Description</div></th>
      <th width="845" bgcolor="#FFFFFF"><div align="center">Email</div></th>
      <th width="845" bgcolor="#FFFFFF"><div align="center">Superior</div></th>
      <th width="171" bgcolor="#FFFFFF">Manage</th>
    </tr>
    <%for(int i = 0; i < users.size(); i++){ %>
    <tr>
      <td bgcolor="#FFFFFF"><div align="center"><%=users.get(i).getName() %></div></td>
      <td bgcolor="#FFFFFF"><%=StringUtils.replace(users.get(i).getDescription(), "\r\n","<br/>")%></td>
      <td bgcolor="#FFFFFF"><%=users.get(i).getEmail()%></td>
      <%Customer superior = userService.getSuperiorUser(users.get(i).getUserid()+""); %>
      <td bgcolor="#FFFFFF"><%= superior != null ? superior.getName():""%></td>
      <td bgcolor="#FFFFFF"><div align="center">
      <a onClick="return checkDel();" href="users.jsp?action=delete&userid=<%=users.get(i).getUserid()%>">Delete</a>
      <a  href="addUser.jsp?action=edit&userid=<%=users.get(i).getUserid()%>">Modify</a>
      </div></td>
    </tr>
    <%} 
    if(users.size() == 0){%>
       <tr>
      <td bgcolor="#FFFFFF" colspan="3"><div align="center">no models found.</div></td>
    </tr> 
    <%} %>    
  </table>
</form>
</body>
</html>